<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>动态时钟</title>
	</head>
	<body>
		<h1 id="showDateDiv"></h1>
		<button type="button" onclick="stopDate()">时间停止</button>
		<button type="button" onclick="startDate()">时间开始</button>
	</body>
	<script type="text/javascript">
		// 获取当前date对象
		function showDateFun(){
			var mydate = new Date();
			var year = mydate.getFullYear();
			var month = mydate.getMonth()+1;
			var day = mydate.getDate();
			var hour = mydate.getHours();
			var minute = mydate.getMinutes();
			var second = mydate.getSeconds();
			if(second<10){
				second = "0"+second;
			}
			
			var showDate = year+"年"+month+"月"+day+"日  "
				+ hour+"："+minute+"："+second;
			document.getElementById("showDateDiv").innerHTML=showDate;
		}
		
		var dateInterval = setInterval("showDateFun()",1000);
		//setTimeout("showDateFun()",2000);
		function stopDate(){
			clearInterval(dateInterval);
		}
		function startDate(){
			dateInterval = setInterval("showDateFun()",1000);
		}
	</script>
</html>
